package com.frikinet.lifeguard.dao;

import com.frikinet.lifeguard.model.Comment;
import com.frikinet.lifeguard.model.Post;
import com.frikinet.lifeguard.util.HibernateUtil;

public class PostDAO
{
	public static void saveOrUpdate(Post post)
	{
		HibernateUtil.saveOrUpdate(post);
		HibernateUtil.saveOrUpdate(post.getComments());
	}
	
	public static void delete(Post post)
	{
		for(Comment comment: post.getComments())
		{
			HibernateUtil.delete(comment);
		}
		post.getComments().clear();
		PostImageDAO.delete(post.getUid());
		HibernateUtil.delete(post);
	}
}
